package com.hbnu.system.controller;

import com.hbnu.system.core.base.Rest;
import com.hbnu.system.model.entity.Dept;
import com.hbnu.system.service.IDeptService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/dept")
@Api(tags = "院系部门模块")
public class DeptController {
    @Autowired
    private IDeptService iDeptService;

    @ApiOperation("院系添加")
    @PostMapping("/addDept")
    public Rest<Boolean> addDept(@RequestBody Dept dept){
        boolean add = iDeptService.addDept(dept);
        return add ? Rest.success():Rest.failed();
    }

    @ApiOperation("获取院系列表")
    @GetMapping("/getDepts")
    public Rest<List<Dept>> getDepts(){
        List<Dept> deptList = iDeptService.getDeptList();
        return Rest.success(deptList);
    }

    @ApiOperation("院系-修改")
    @PostMapping("/updateDept")
    public Rest<Boolean> updateDept(@RequestBody Dept dept){
        boolean update = iDeptService.updateDept(dept);
        return update ? Rest.success() : Rest.failed();
    }

    @ApiOperation("院系-删除")
    @GetMapping("/deleteDept")
    public Rest<Boolean> deleteDept(String deptID){
        boolean delete = iDeptService.deleteDept(deptID);
        return delete ? Rest.success() : Rest.failed();
    }

    //根据名称进行查询
    @ApiOperation("根据名称进行查询")
    @GetMapping("/getDeptByName")
    public Rest<List<Dept>> getDeptByName(String deptName){
        List<Dept> depts = iDeptService.getDeptByName(deptName);
        return Rest.success(depts);
    }

}
